//---------------------------------------------------------------------------


#pragma hdrstop

#include "TDxfParameter.h"


//---------------------------------------------------------------------------


#pragma package(smart_init)
__fastcall TColors::TColors()
{
	int i;
	for (i = 0; i < 255; i++) {
		push_back(i + 1);
	}
}

void __fastcall TColors::Save(const int FileHandle)
{
	int i, q;
	q = size();
	WriteFloat(FileHandle, q);
	for (i = 0; i < q; i++) {
	   WriteFloat(FileHandle, at(i));
	}
}

void __fastcall TColors::Load(const int FileHandle)
{
	int i, q;
	q = ReadFloat(FileHandle);
	resize(q);
	for (i = 0; i < q; i++) {
	   at(i) = ReadFloat(FileHandle);
	}
}

__fastcall TDxfParameter::TDxfParameter()
{
	SetMeasurement(MetricMeasurement);
	return;
}

__fastcall TDxfParameter::TDxfParameter(const eMeasurement Measurement)
{
	SetMeasurement(Measurement);
	return;
}

void __fastcall TDxfParameter::SetMeasurement(const eMeasurement Measurement)
{
	switch (Measurement) {
		case MetricMeasurement:
			PlanX = 0;
			PlanY = 0;
			BaseX = 0;
			ProfileX = 0;
			Interval = 2;
			SpeedScale = 50;
			TimeSpeedScale = 50;
			CurveWidth = SwitchWidth = HumpWidth = 7;
			TrackRetarderWidth = 4;
			ProfileHeight = 30;
			LengthMeasurementRate = 1;
			SpeedMeasurementRate = 1;
			TenHeight = 10;
			break;
		case BritishMeasurement:
			PlanX = 0;
			PlanY = 0;
			BaseX = 0;
			ProfileX = 0;
			Interval = 6;
			SpeedScale = 300;            // 1 mph = 300 unit;
			TimeSpeedScale = 100;         // 1 mph = 100s
			CurveWidth = SwitchWidth = HumpWidth = 30;
			TrackRetarderWidth = 10;
			ProfileHeight = 210;
			LengthMeasurementRate = 3.28084;
			SpeedMeasurementRate = 2.2374;
			TenHeight = 30;
			break;
	}
	FontHeight = 0.4 * ProfileHeight - 2 * Interval;
	FontWidthHeightScale = 0.7;
	HundredHeight = 2 * TenHeight;
	return;
}

void __fastcall TDxfParameter::Initialize(void)
{
	ProfileY = PlanY + MaxPlanWidth() + Interval;
	BaseY = ProfileY + Interval + ProfileHeight;
	FontWidth = FontHeight * FontWidthHeightScale;
	TimeScale = SpeedScale / TimeSpeedScale;
	return;
}

float __fastcall TDxfParameter::MaxPlanWidth(void)
{
	float m;
	m = m > SwitchWidth ? m : SwitchWidth;
	m = m > CurveWidth ? m : CurveWidth;
	m = m > HumpWidth ? m : HumpWidth;
	m = m > TrackRetarderWidth ? m : TrackRetarderWidth;
	return m;
}
